/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package almacenamiento;

import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
 *
 * @author SaHa
 */
public class Tarea_Leer_N_Tuplas 
{
    public static void main(String args[]) 
    {
        Scanner in = new Scanner(System.in);

        List<Atributo> attrs = new ArrayList<Atributo>();
        attrs.add(new Atributo("character", Character.class));
        attrs.add(new Atributo("byte", Byte.class));
        attrs.add(new Atributo("short", Short.class));
        attrs.add(new Atributo("integer", Integer.class));
        attrs.add(new Atributo("long", Long.class));
        attrs.add(new Atributo("float", Float.class));
        attrs.add(new Atributo("double", Double.class));
        attrs.add(new Atributo("string", String.class));
        Relacion rel = new Relacion(attrs);


        System.out.print("Ingrese el numero de tuplas  que desea registrar: ");
        int nroTuplas = in.nextInt();
        
        List<GestorIOTupla> listas = new ArrayList<GestorIOTupla>();
        List<Tupla> Tupla = new ArrayList<Tupla>();

        for (int i = 0; i < nroTuplas; i++)
        {            
            System.out.println("Tupla Nro : "+(i+1));            
            System.out.println("Ingrese los siguientes datos: ");
            List<Comparable> ListaTuplas = new ArrayList<Comparable>();
            System.out.println("Char:");
            Scanner n1=new Scanner(System.in);
            ListaTuplas.add(new Character(n1.next().toCharArray()[0]));
            System.out.println("Byte:");
            ListaTuplas.add(new Byte(n1.nextByte()));
            System.out.println("Short:");
            ListaTuplas.add(n1.nextShort());
            System.out.println("Integer:");
            ListaTuplas.add(new Integer(n1.nextInt()));
            System.out.println("Long:");
            ListaTuplas.add(n1.nextLong());
            System.out.println("Float:");
            ListaTuplas.add(Float.parseFloat(n1.next()));
            System.out.println("Double:");
            ListaTuplas.add(Double.parseDouble(n1.next()));
            System.out.println("String:");
            ListaTuplas.add(n1.next());

            Tupla t = new Tupla(new IdentificadorTupla("redes "+i, i), ListaTuplas);
            GestorIOTupla man = new GestorIOTupla(rel, "redes "+i);

            Tupla.add(t);
            listas.add(man);
        }
       
        int inicio =0;
        
        for (int j = 0; j < nroTuplas; j++) 
        {
            Tupla t = Tupla.get(j);
            System.out.println("------------------------------------------");
            System.out.println("Escribiendo la Tupla..." + t);
            byte[] bytes = new byte[1024];
            GestorIOTupla a  = listas.get(j);
            a.escribirTupla(t, bytes, inicio);

            System.out.println("Mostrando el arreglo de bytes: "+bytes);

            System.out.println("Leendo la Tupla...");            
            Par<Tupla, Integer> st = a.leerTupla(bytes, inicio);
            System.out.println(st);
            inicio+=st.segundo;
            System.out.println("-------------------------------------------");
            System.out.println();
        }
    }   
}
